<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
$(function(){
	<c:choose>
	<c:when test="${ref.saveType=='modify'}">
	$('#frmAdmdiv input[name="id"]').val('${admdivision.id}');
	$('#frmAdmdiv input[name="adname"]').val('${admdivision.adname}');
	$('#frmAdmdiv input[name="adcode"]').val('${admdivision.adcode}');
	$('#frmAdmdiv input[name="parentcode"]').val('${parentAdmdiv.adcode}');
	$('#frmAdmdiv input[name="parentname"]').val('${parentAdmdiv.adname}');
	</c:when>
	<c:otherwise>
	$('#frmAdmdiv input[name="adcode"]').val('${ref.newcode}');
	$('#frmAdmdiv input[name="parentcode"]').val('${parentAdmdiv.adcode}');
	$('#frmAdmdiv input[name="parentname"]').val('${parentAdmdiv.adname}');
	</c:otherwise>
	</c:choose>
})

function saveAdmdiv(){
	if ($('#frmAdmdiv').form('validate')) {
		var data = $('#frmAdmdiv').serialize();
		var adcode = $('#frmAdmdiv input[name="adcode"]').val();
		var adname = $('#frmAdmdiv input[name="adname"]').val();
		$.ajax({
			url: '<c:url value="/system/admdiv/doSaveAdmdiv.do"/>',
			type: 'POST',
			data: data,
			beforeSend: function(XmlHttpRequest, textStatus, errorThrown) {
				$.messager.progress({
					title:'提示',
					msg:'正在执行数据操作，请稍待...'
				});
			},
			success: function(result) {
				$.messager.progress('close');
				if(!result.success) {
					$.messager.alert('错误', result.data, 'error');
				}
				else {
					$.messager.alert('提示', result.data , 'info');
					$('#tblListAdmdiv').datagrid('clearSelections').datagrid('reload');
					var node = $('#admdivTree').tree('getSelected');  //组织节点须选中
					if (node == null){
						node = $('#admdivTree').tree('getRoot');
					}
					<c:choose>
					<c:when test="${ref.saveType=='modify'}">
					$('#admdivTree').tree('reload', node.target);
					</c:when>
					<c:otherwise>
					$('#admdivTree').tree('append',{
						parent: (node?node.target:null),
						data:[{
							id: adcode,
							text: adname
						}]
					});
					</c:otherwise>
					</c:choose>
					
					$('#dlgAdmdiv').dialog('close');
				}
			},
			complete: function (XMLHttpRequest, textStatus) {
			}
		});
	}
}
</script>
<div style="padding: 5px;">
			<form id="frmAdmdiv" method="post" style="margin:0;padding:0">
			<table  align="center" cellpadding="0" cellspacing="0">
				<tr>
					<td><font color="red">*</font>上级区划：</td>
					<td>
						<input id="parentname" name="parentname" style="width:200px" class="easyui-validatebox" readOnly/>
						<input type="hidden" name="parentcode" id="parentcode"/>		
						<input type="hidden" name="id" id="id"/>
					</td>
				</tr>			
				<tr>
					<td><font color="red">*</font>区划编码：</td>
					<td>
						<input id="adcode" name="adcode" style="width:200px" class="easyui-validatebox" required="true" maxlength="6"/>
					</td>
				</tr>
				<tr>
					<td><font color="red">*</font>区划名称：</td>
					<td>
						<input id="adname" name="adname" style="width:200px" class="easyui-validatebox" required="true"/>
					</td>
				</tr>
			</table>
			</form>
</div>